package q1;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class ServeurSocket {

	public ServeurSocket(int portNumber) {
		try {
			ServerSocket srvr = new ServerSocket(portNumber);
			Socket skt = srvr.accept();
			BufferedReader in = new BufferedReader(
					new InputStreamReader(skt.getInputStream()));
			System.out.println("Awaiting String from Client: '");
			
			String text = "";

			do {
				if(in.ready()) {
					text = in.readLine(); // Read one line and output
					if(!text.equalsIgnoreCase("EXIT"))
						System.out.println(text);
				}
			
			} while(!text.equalsIgnoreCase("EXIT"));

			System.out.println();

			in.close();
			skt.close();
			srvr.close();
		}
		catch(Exception e) {
			System.out.print("Whoops! It didn't work!\n");
		}	
	}


}